<template>
	<view>
		<view class="nav-tab">
			<view 
				class="li" 
				v-for="(item, index) in tabs" 
				:key="index" 
				:class="currentTab==index?'current':''"
				@click="onTabClick(index)"
			>
				<text>{{item.name}}</text>
			</view>
		</view>
		
		<view class="list">
		     <view class="list-cell" v-for="(item,index) in list" :key="index">
				 <view class="cell">
					<image :src="item.pic"></image>
					<view class="cell-right">
						<view class="title">
							<text>{{item.title}}</text>
						</view>
						<view class="date">
							<view></view>
							<text>{{item.add_time}}</text>
						</view>
					</view>
				 </view>
			 </view>
		</view>	 
	</view>
</template>

<script>
	import {
		JSMRequest
	} from '@/module/api'
	export default {
		
		data() {
			return {
				tabs: [],
				currentTab: 0,
				list:[]
			}
		},
		
		onLoad() {
			this.getCateData()
		},
		
		methods: {
			onTabClick (index) {
				if(this.currentTab == index) return
				this.currentTab = index
				this.getPageData()
			},
			
			getCateData () {
				let _t = this				
				JSMRequest({
					tag: "jsm-article-cate",
					method: "POST",
					params: {
						
					}
				}).then(({data}) => {
					_t.tabs = data
					_t.getPageData()
				}).catch(e => {
					
				})
			},
			
			getPageData(){
				let _t = this;
				JSMRequest({
					tag: "jsm-article-index",
					method: "POST",
					params: {
						cat_id:_t.tabs[_t.currentTab].id
					}
				}).then(({data}) => {
					_t.list = data;
					console.log(data)
				}).catch(e => {
					
				})
			},
		}
	}
</script>

<style lang="less" >
page {
	background-color: #EEEEEE;
}
.nav-tab{
        width: 100%;
        position: absolute;
        height: 80px;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
		overflow-x: auto;
        z-index: 10;

        .li{
            width: 150px;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;

            text{
                color: #999;
                font-size: 26px;
            }
			&.current{
                text{
                    color: red;
                }
            }
		}
}

.list {
	margin-top: 90px;
}

.cell {
	margin-top: 1px;
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: 20px 20px 20px 20px;
	background-color: white;
	image {
		height: 128px;
		width: 128px;
		border-radius: 20px;
	}
	.cell-right {
		padding-left: 20px;
		padding-right: 20px;
		height: 128px;
		width: 77%;
		display: flex;
		flex-direction: column;
		align-content:space-between;
		.title {
			top: 0;
			text {
				font-size: 32px;
			}
		}
		.date {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			margin-top: 20px;
			text {
				font-size: 28px;
				color: #6E6E6E;
			}
		}
	}
}
</style>
